<meta args="params"/>
<form class="form-horizontal" id="form" s="form,datac,nda,valid" s-data="params">
    <table class="table table-bordered table-condensed table-middle">
        <tr>
            <td><code>id</code></td>
            <td class="form-inline">
                <input autocomplete="off" type="number" s-valid-error="require(),number()" id="id" class="form-control" name="id" />
                <input type="button" value="选择商品" class="btn btn-primary btn-sm btn-outline" s-click="selectItem()" />
            </td>
        </tr>
    </table>
</form>
<script>
    S.getParams = function() {
        var deferred = $.Deferred();
        $form.validate().done(function() {
            deferred.resolve($form.node.serialize());
        })
        return deferred;
    }

    function selectItem() {
        S.popupOpen('/commission-item/commission-item-selector.html', {multi: false}).done(function(itemList) {
            if(itemList && itemList.length) {
                S.post("/api/commissionItem/fetch", {
                    itemList: JSON.stringify(itemList)
                }).done(function(_itemList) {
                    $id.node.val(_itemList[0].id)
                })
            }
        })
    }
</script>